package com.bb.services.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.bb.dao.UserDao;
import com.bb.pojo.User;
import com.bb.service.UserService;
import com.bb.util.GetSqlSessionUtil;

public class UserServiceImpl implements UserService{
	/*查询出所有的用户*/
	public List<User> getAllUser(){
		SqlSession sqlSession = new GetSqlSessionUtil().getSqlSession();
		UserDao mapper = sqlSession.getMapper(UserDao.class);
		
		return mapper.list();
	}
	/*登录*/
	public User chkLogin(String username){
		SqlSession sqlSession = new GetSqlSessionUtil().getSqlSession();
		UserDao mapper = sqlSession.getMapper(UserDao.class);
		User userLogin = mapper.userLogin(username);
		
		return userLogin;
	}
	
	@Override
	public User getOneUser(int u_id) {
		SqlSession sqlSession = new GetSqlSessionUtil().getSqlSession();
		UserDao mapper = sqlSession.getMapper(UserDao.class);
		User selectOneuser = mapper.selectOneuser(u_id);
		
		return selectOneuser;
	}
	/*处理用户的修改信息*/
	@Override
	public int updateUser(User user) {
		SqlSession sqlSession = new GetSqlSessionUtil().getSqlSession();
		UserDao mapper = sqlSession.getMapper(UserDao.class);
		int i = mapper.uptUser(user);
		sqlSession.commit();
		
		return i;
	}
	/*处理用户的删除*/
	@Override
	public int delUser(int u_id) {
		SqlSession sqlSession = new GetSqlSessionUtil().getSqlSession();
		UserDao mapper = sqlSession.getMapper(UserDao.class);
		int i = 0;
		i =  mapper.deleUser(u_id);
		sqlSession.commit();
		return i;
	}
	//处理添加数据
	@Override
	public int addUser(User user) {
		SqlSession sqlSession = new GetSqlSessionUtil().getSqlSession();
		UserDao mapper = sqlSession.getMapper(UserDao.class);
		int i = 0;
		i = mapper.insertUser(user);
		sqlSession.commit();
		return i;
	}
}
